package com.springtools;

import java.io.IOException;
import java.io.InputStream;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.FileSystemResource;
import org.springframework.core.io.Resource;

public class FileSourceExample {
	public static void main(String[] args) {
		try {
			String filePath = "D:/WORKSPACE/MyEclipse/SpringTools/bin/file1.txt";
			// ① 使用系统文件路径方式加载文件
			Resource res1 = new FileSystemResource(filePath);
			// ② 使用类路径方式加载文件
			Resource res2 = new ClassPathResource("file1.txt");
			InputStream ins1 = res1.getInputStream();
			InputStream ins2 = res2.getInputStream();
			System.out.println("res1:" + res1.getFilename());
			System.out.println("res2:" + res2.getFilename());

			res1.createRelative("file1.txt");

		} catch (IOException e) {
			e.printStackTrace();
		}
	}
}
